package com.hippo.module.sys.controller;

import com.github.pagehelper.PageInfo;
import com.hippo.api.sys.entity.DistrictEntity;
import com.hippo.common.base.model.ResponseDataModel;
import com.hippo.common.base.util.ResponseDataUtil;
import com.hippo.module.sys.service.DistrictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * <p>
 * Title: DistrictController.java
 * </p>
 * Description: 区域
 * <p>
 * Modify histoty:
 *
 * @author cjh
 * @version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/district")
public class DistrictController {

    @Autowired
    private DistrictService districtService;

    /**
     * 初始区域管理数据
     *
     * @param request
     * @return
     */
    @GetMapping("/initDistrictManageData")
    public ResponseDataModel initDeptManageData(HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        Map<String,Object> map = new HashMap<>();
        return ResponseDataUtil.createResponseData(true,"初始系统信息数据成功",map);
    }


    /**
     * 根据条件分页查询区域
     *
     * @param parameter
     * @return
     */
    @GetMapping("/queryDistrictByConditionPaging")
    public ResponseDataModel queryDistrictByConditionPaging(DistrictEntity parameter) {
        ResponseDataModel resultData = new ResponseDataModel();
        try {
            PageInfo<DistrictEntity> result = this.districtService
                    .queryDistrictByConditionPaging(parameter);
            if (null != result) {
                resultData.setSuccess(true);
                resultData.setResponseData(result);
                log.info("根据条件分页查询区域成功！");
            } else {
                resultData.setSuccess(false);
                resultData.setMsg("根据条件分页查询区域未成功！");
                log.error("根据条件分页查询区域未成功");
            }

        } catch (Exception e) {
            resultData.setSuccess(false);
            resultData.setMsg("根据条件分页查询区域失败！");
            e.printStackTrace();
            log.error("根据条件分页查询区域失败,错误——>" + e);
        }

        return resultData;
    }

}
